var basePath = getBasePath();
//录入条目的数量
var testProdInfoItemCount = 0;
//1.查询所有的录入条目
function getAllTestProdInfoItem(labcode) {
	$.ajax({
		type : "get",
		url : basePath +config.bxxs.apiPath+"/TestProdInfoItem/getAllTestProdInfoItem",
		data : {
			labcode : labcode
		},
		success : function(msg) {
			testProdInfoItemCount = msg.length;
			var item = "<thead>" + "<tr>" +
				"<th>台位名称</th>" +
				"<th>是否在测</th>" +
				"<th>开测时间</th>" +
				"<th>停测时间</th>";
			$("#table_content tr").eq(1).remove();
			for (var i = 0; i < msg.length; i++) {
				//拼接字符串
				item = item + "<th>" + (msg[i].itemname) + "</th>";
			}
			item = item + "</tr>" + "</thead>";
			console.error(item)
		//			$("#table_content").append(item);
		},
		error : function(e) {
			alert("网页发生错误：", e, "error");
		}
	});
}

//2.获取所有的测试元数据
function getAllTestProdInfoValue(labcode, pageNum) {
	let layerid = layer.msg('加载中', {
		icon : 16,
		shade : 0.4,
		time : false //取消自动关闭
	});
	$.ajax({
		type : "get",
		url : basePath +config.bxxs.apiPath+"/TestProdInfoValue/getAllTestProdInfoValue",
		data : {
			labcode : labcode,
			pageNum : pageNum
		},
		success : function(msg) {
			layer.close(layerid); //手动关闭
			var item = "<tbody>";
			$("#table_content tbody tr").remove();
			for (var i = 0; i < msg.list.length; i++) {
				//判断是否开测
				let testnow = (msg.list[i].testnow == "0" ? "否" : "是");
				//根据台位编码获取台位名称
				let unitName = getUnitNameByUnitNo(msg.list[i].testunitno);
				if (i % 2) {
					//拼接字符串
					item = item + "<tr>" +
						"<td>" + unitName + "</td>" +
						"<td>" + testnow + "</td>" +
						"<td>" + msg.list[i].begindatetime + "</td>" +
						"<td>" + msg.list[i].enddatetime + "</td>";
					for (var j = 1; j <= testProdInfoItemCount; j++) {
						let itemcontent = "msg.list[i].itemcontent" + j;
						item = item + "<td>" + eval(itemcontent) + "</td>";
					}
					item = item + "</tr>";
				} else {
					//拼接字符串
					item = item + "<tr>" +
						"<td>" + unitName + "</td>" +
						"<td>" + testnow + "</td>" +
						"<td>" + msg.list[i].begindatetime + "</td>" +
						"<td>" + msg.list[i].enddatetime + "</td>";
					for (var j = 1; j <= testProdInfoItemCount; j++) {
						let itemcontent = "msg.list[i].itemcontent" + j;
						item = item + "<td>" + eval(itemcontent) + "</td>";
					}
					item = item + "</tr>";
				}

			}
			item = item + "</tbody>";
			$("#table_content").append(item);
			var pageNum = msg.pageNum;
			var total = msg.total;
			var pages = msg.pages;
			//设置页码
			$("#total").text(total);
			$("#pageNum").text(pageNum);
			$("#pages").text(pages);
		},
		error : function(e) {
			alert("网页发生错误：", e, "error");
		}
	});

}